package com.yuntsg.ruiijn.paperana.test;

import com.aspose.words.*;
import common.util.ExtractUtil;
import lombok.SneakyThrows;

public class 处理页眉页脚测试 {
    @SneakyThrows
    public static void main(String[] args) {


        boolean localLicense = ExtractUtil.getLocalLicense();
        System.out.println(localLicense);

        String PATH = "D:\\Users\\55419\\Desktop\\新版本报告\\宁医大\\";
        String fromPath = "D:\\Users\\55419\\Desktop\\新版本报告\\宁医大\\宁医大总院文章9.docx";
        Document doc = new Document(fromPath);

        DocumentBuilder builder = new DocumentBuilder(doc);

        builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
        builder.startTable();
        builder.getCellFormat().clearFormatting();
        builder.insertCell();
        builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(100 / 3));
        //添加页码
        builder.write("第aaaaa ");
        builder.insertField("PAGE", "");
        builder.write(" of ");
        builder.insertField("NUMPAGES", "");

        builder.getCurrentParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
        builder.insertCell();
        builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(100 * 2 / 3));

        builder.write("(C) 2001 Aspose Pty Ltd. All rights reserved.");
        builder.getCurrentParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);

        builder.endRow();
        builder.endTable();
//        builder.

        doc.save(PATH + "test1.docx");


    }
}
